# -*- coding: utf-8 -*-
import os
import logging
import time

logt = time.strftime('%Y-%m-%d_%H点%M分')
today = time.strftime('%Y-%m-%d')

api_path = os.path.dirname(os.path.dirname(__file__))
# 创建当天目录
logs_path = api_path + "/logs/" + today
if not os.path.exists(logs_path):
    os.makedirs(logs_path, exist_ok=True)

logger = logging.getLogger('apilog')
logger.setLevel(logging.DEBUG)

format = logging.Formatter("%(asctime)s|%(levelname)8s|%(filename)5s|:%(lineno)s|%(message)s")

fl = logging.FileHandler(filename=f"{logs_path}\\{logt}.log", mode='w', encoding='utf-8')  # 输出文件

fl.setFormatter(format)  # 输出格式

sl = logging.StreamHandler()
sl.setFormatter(format)

logger.addHandler(fl)  # 输出到api.log文件
logger.addHandler(sl)  # 输出到控制台
